home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part1 / 8913 < prev    next >
Encoding:
Text File  |  1996-08-05  |  4.0 KB  |  113 lines

  1. Path: obibicut.cs.rmit.edu.au!dale
  2. From: Dale Stanbrough <dale@goanna.cs.rmit.EDU.AU>
  3. Newsgroups: comp.lang.ada,comp.lang.c++
  4. Subject: Re: on OO differnces between Ada95 and C++
  5. Date: 27 Feb 1996 11:47:02 GMT
  6. Organization: Royal Melbourne Institute of Technology
  7. Distribution: world
  8. Message-ID: <4guqvm$4cn@goanna.cs.rmit.EDU.AU>
  9. References: <4gbq7q$g08@qualcomm.com> <4gt3ag$76m@druid.borland.com> <DnDuEG.8Kx@bton.ac.uk> <DnDuA4.8GC@bton.ac.uk>
  10. NNTP-Posting-Host: obibicut.cs.rmit.edu.au
  11. Mime-Version: 1.0
  12. Content-Type: text/plain; charset=ISO-8859-1
  13. Content-Transfer-Encoding: 8bit
  14. X-Newsreader: Nuntius 2.0.4_68K
  15. X-XXMessage-ID: <AD593B61D5011B17@obibicut.cs.rmit.edu.au>
  16. X-XXDate: Tue, 27 Feb 1996 06:51:13 GMT
  17.  
  18. John English, je@bton.ac.uk writes:
  19. ": If what you say was the case, then types defined in package "A"
  20. : will be seen by clients to a package "B" where "B" has with'ed A. But
  21. : it is not so. Clients of "B" must also 'with' "A" to see types
  22. defined
  23. : in "A" even though "B: has allready  with'ed "A".
  24.  
  25. If you're right this would be a real pain.  Clients of a package would
  26. have
  27. to know (recursively) what other packages the spec(s) reference; if the
  28. spec for X "withs" a package Y so it can use type Y.T as a procedure
  29. parameter then you wouldn't be able to use X without Y (i.e. "with X"
  30. on its own would be useless; you'd have to have "with X, Y" and
  31. probably
  32. other things as well if Y has any "with" clauses in its specification.
  33.  
  34. This is such a horrible concept that I'm inclined to believe GNAT, but
  35. if anyone who can understand all the subleties of the visibility rules
  36. can give us all a definitive explanation in words of sufficiently few
  37. syllables that Bears of Very Little Brain like me can understand, I for
  38. one would be profoundly grateful."
  39.  
  40. Au Contraire, it's a great concept. It is SO nice to be able to see,
  41. from the top of a listing, just what the relationship b/w the unit 
  42. you are looking at to the rest of the system is.
  43.  
  44. I *hate* transtive 'with'ing relationships! When you read the code
  45. of C/C++, you may have one #include at the top, but your code
  46. references
  47. all sorts of types/functions etc. Where do they come from? What range
  48. of packages do I have to look at before I can find the declarations?
  49. Should I do a broad search, or a depth first search on the #include
  50. files
  51. when looking for the declarations?
  52. In Ada, with it's 'flat' view of 'with'ings (compared to C's deep
  53. #include
  54. model) you can easily see the level of coupling of a
  55. package/compilation
  56. unit.
  57.  
  58. A simple explanation is perhaps...
  59.  
  60.     "with"ing never extends beyond the units you have explicity "with"ed.
  61.     If you need something that they have "with"ed, then you have to 
  62.     with it as well. "With"ing is only ever one unit deep.
  63.     
  64. A simple example
  65.     ----------------------------------
  66.     package a is
  67.         type alpha is...
  68.         
  69.         function X return alpha;
  70.     end a;
  71.     
  72.     ----------------------------------
  73.     with a;
  74.     package b is
  75.         type beta is
  76.         
  77.         procedure Y(item:       alpha);
  78.         procedure Z(item:in out beta);
  79.     end b;
  80.     
  81.     ----------------------------------
  82.     -- if you use resources from A,        -- If you don't use resources from
  83.     -- then you have to "with" A.        -- A, then you can ignore it.
  84.     with A;
  85.     with B;                                with B;
  86.         
  87.     procedure main is                    procedure main is
  88.         stuff    :A.alpha    := A.X;            stuff    :B.beta;
  89.     begin                                begin
  90.         B.Y(stuff);                            B.Z(stuff);
  91.     end;                                end;
  92.     
  93. Important to note that if procedure main isn't going to declare any
  94. alpha values, or call B.Y, then it doesn't need to with A at all.
  95.  
  96. The fact that B has "with"ed A can be viewed as a compositional
  97. legacy from the construction of B. It has little to do with how
  98. procedure main is constructed.
  99.  
  100. If "main" want's to use resources from A, then it explicity has to
  101. declare it's intent for all the world to see.
  102.  
  103. The use clause only means you don't have to use dot notation (e.g.
  104. B.Y) when accessing resources from the package.
  105.  
  106. I suspect that if you examine some real code that you will not
  107. find too great a list of "with"ed units (esp. with well designed
  108. code). Even if it were, I wouldn't be too concerned, as it aids
  109. the reader of the code.
  110.  
  111.  
  112. Dale
  113.